def is_point_in_poly(point, polygon):
    """
    判断点是否在多边形内部（含边界）
    :param point: 待判断点，格式 (x, y)
    :param polygon: 多边形顶点列表，格式 [(x0, y0), (x1, y1), ...]
    :return: True（内部或边界）/ False（外部）
    """
    x, y = point
    n = len(polygon)
    inside = False

    # 遍历所有边（从最后一个顶点到第一个顶点闭合）
    p1x, p1y = polygon[0]
    for i in range(n + 1):
        # 获取当前边的两个端点
        p2x, p2y = polygon[i % n]

        # 检查点是否在边的Y值范围内
        if min(p1y, p2y) < y <= max(p1y, p2y):
            # 计算射线与边的交点X坐标
            if p1y != p2y:  # 避免除零错误
                x_intersect = (y - p1y) * (p2x - p1x) / (p2y - p1y) + p1x

            # 处理水平边（点在边上直接返回True）
            if p1y == p2y:
                if min(p1x, p2x) <= x <= max(p1x, p2x):
                    return True
            # 当交点在点右侧时，标记奇偶性翻转
            elif x < x_intersect:
                inside = not inside

        # 移动到下一条边
        p1x, p1y = p2x, p2y

    return inside


def is_all_points_inside_poly(local_path_x, local_path_y, local_field_boundary_poly_buffered):
    local_field_boundary_poly_buffered_points_list = [ [lon, lat] for lon, lat in local_field_boundary_poly_buffered.exterior.coords]

    is_all_points_inside = True

    for i in range(len(local_path_x)):
        current_path_point = [ local_path_x[i], local_path_y[i] ]
        # 如果当前点 不在 内缩后的边界内部
        if not is_point_in_poly(current_path_point, local_field_boundary_poly_buffered_points_list):
            is_all_points_inside = False
            break


    return is_all_points_inside
